﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
/// <summary>
/// Summary description for CalEvents
/// </summary>
public class CalEvents
{
    public cEvents _events;
	public CalEvents()
	{
        //xmlDoc.LoadXml("../XmlResource/jewishcal.xml");
        HttpContext MyContext = HttpContext.Current;
        String filePath=string.Empty;    // folder

        filePath = MyContext.Server.MapPath("XmlResource/jewishcal.xml");

        _events = new cEvents();

        XmlSerializer serializer = new XmlSerializer(typeof(cEvents));
        
        StreamReader reader = new StreamReader(filePath);
        try
        {
            _events = (cEvents)serializer.Deserialize(reader);
        }
        catch { }
        finally
        {
            reader.Close();
        }
	}

    public List<CalEvent> findEvents(DateTime date)
    {
        List<CalEvent> lst = new List<CalEvent>();

        foreach (CalEvent item in _events.calEvent)
        {
            if (DateTime.Parse(item.Date) == date)
            {
                lst.Add(item);
            }
        }
        return lst;
    }
}

[Serializable]
public class CalEvent
{
    [XmlElement("Date")]
    public string Date;
    [XmlElement("Summary")]
    public string Summary;
    [XmlElement("Description")]
    public string Description;
}

[XmlRootAttribute("Root", Namespace = "", IsNullable = false)]
public class cEvents
{
    [XmlArray("Events")]
    [XmlArrayItem("Event", typeof(CalEvent), IsNullable = false)]
    public CalEvent[] calEvent;
}